﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entetities;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace DAL
{
    public class DiaChiDAL
    {
        private string stringconnect = ConfigurationManager.ConnectionStrings["QLST"].ConnectionString;
        public DiaChiDAL()
        {
        }
        public int InsertDiaChi(DiaChi dc)
        {
            SqlConnection conn = new SqlConnection(stringconnect);
            conn.Open();
            int madiachi = 0;
            SqlCommand cmd = new SqlCommand("add_diachi", conn);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter p1 = new SqlParameter("@Madiachi",madiachi);
            p1.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(p1);
            SqlParameter p2 = new SqlParameter("@AddressLine1", dc.AddressLine1);
            cmd.Parameters.Add(p2);
            SqlParameter p3 = new SqlParameter("@Quanhuyen", dc.Quanhuyen);
            if (dc.Quanhuyen == "")
            {
                p3.Value = DBNull.Value;
            }
            cmd.Parameters.Add(p3);
            SqlParameter p4 = new SqlParameter("@Tinhthanh", dc.Tinhthanh);
            if (dc.Tinhthanh == "")
            {
                p4.Value = DBNull.Value;
            }
            cmd.Parameters.Add(p4);
            SqlParameter p5 = new SqlParameter("@Quocgia", dc.Quocgia);
            cmd.Parameters.Add(p5);

            cmd.ExecuteNonQuery();

            madiachi = (int)p1.Value;

            return madiachi;
        }
    }
}
